var handleClickGen = function () {
  genUser();
};

var handleClickIsFix = function () {
  var disFix = document.querySelector("#is-fix");
  var dlist = document.querySelector("#data-list");
  if (disFix.checked) {
    dlist.style.height = "500px";
    dlist.style.overflowY = "scroll";
  } else {
    dlist.style.height = "auto";
    dlist.style.overflowY = "scroll";
  }
};

/**
 * 生成随机数
 * @param {number} minValue
 * @param {number} maxValue
 */
var genRandom = function (minValue, maxValue) {
  var ran = Math.random();
  var num = Math.floor(ran * maxValue) + minValue;
  return num;
};

var genUser = function () {
  var total = 0;
  var dlist = document.querySelector("#data-list");
  dlist.innerHTML="";
  var dcount = parseInt(document.querySelector("#user-count").value);
  var dtotal = document.querySelector("#total");
  for (var i = 0; i < dcount; i++) {
    var dtr = document.createElement("tr");
    var dtd1 = document.createElement("td");
    var dtd2 = document.createElement("td");
    var dtd3 = document.createElement("td");
    dtd1.innerText = i;
    dtd2.innerText = "张三(" + i + ")";
    var ranNum = genRandom(10, 100);
    total += ranNum;
    dtd3.innerText = ranNum;

    dtr.appendChild(dtd1);
    dtr.appendChild(dtd2);
    dtr.appendChild(dtd3);

    dlist.appendChild(dtr);
  }
  dtotal.innerText = total;
};

genUser();
